#include "SceneSystem.h"

SceneSystem::SceneSystem(EnginePointer<SettingsManager>& settings, EnginePointer<IMessageQueue>& messages)
	:IEngineSystem(settings, messages)
{
}

SceneSystem::~SceneSystem()
{
	directionalComponents.clear();
	ambientComponents.clear();
	spotComponents.clear();
	pointComponents.clear();
	cameras.clear();
}

HRESULT SceneSystem::RegisterComponent(EnginePointer<IEngineComponent>& component)
{
	if (component->getSystemIdentifier() == getSystemIdentifier())
	{
		if (component->getComponentIdentifier() == DIRECTIONAL_LIGHT_COMPONENT_GUID)
		{
			EnginePointer<DirectionalLightComponent> rComponent = (EnginePointer<DirectionalLightComponent>)component;
			directionalComponents.push_back(rComponent);
		}
		else if (component->getComponentIdentifier() == SPOT_LIGHT_COMPONENT_GUID)
		{
			EnginePointer<SpotLightComponent> rComponent = (EnginePointer<SpotLightComponent>)component;
			spotComponents.push_back(rComponent);
		}
		else if (component->getComponentIdentifier() == POINT_LIGHT_COMPONENT_GUID)
		{
			EnginePointer<PointLightComponent> rComponent = (EnginePointer<PointLightComponent>)component;
			pointComponents.push_back(rComponent);
		}
		else if (component->getComponentIdentifier() == AMBIENT_LIGHT_COMPONENT_GUID)
		{
			EnginePointer<AmbientLightComponent> rComponent = (EnginePointer<AmbientLightComponent>)component;
			ambientComponents.push_back(rComponent);
		}
		else if (component->getComponentIdentifier() == CAMERA_COMPONENT_GUID)
		{
			EnginePointer<ICameraComponent> camera = (EnginePointer<ICameraComponent>)component;
			cameras.push_back(camera);
		}
	}

	return S_OK;
}

GUID SceneSystem::getSystemIdentifier()
{
	return SCENE_SYSTEM_GUID;
}

list<EnginePointer<DirectionalLightComponent>>::iterator SceneSystem::DirectionalComponentsBegin()
{
	return directionalComponents.begin();
}

list<EnginePointer<DirectionalLightComponent>>::iterator SceneSystem::DirectionalComponentsEnd()
{
	return directionalComponents.end();
}

list<EnginePointer<AmbientLightComponent>>::iterator SceneSystem::AmbientComponentsBegin()
{
	return ambientComponents.begin();
}

list<EnginePointer<AmbientLightComponent>>::iterator SceneSystem::AmbientComponentsEnd()
{
	return ambientComponents.end();
}

list<EnginePointer<SpotLightComponent>>::iterator SceneSystem::SpotComponentsBegin()
{
	return spotComponents.begin();
}

list<EnginePointer<SpotLightComponent>>::iterator SceneSystem::SpotComponentsEnd()
{
	return spotComponents.end();
}

list<EnginePointer<PointLightComponent>>::iterator SceneSystem::PointComponentsBegin()
{
	return pointComponents.begin();
}

list<EnginePointer<PointLightComponent>>::iterator SceneSystem::PointComponentsEnd()
{
	return pointComponents.end();
}

list<EnginePointer<ICameraComponent>>::iterator SceneSystem::CamerasBegin()
{
	return cameras.begin();
}

list<EnginePointer<ICameraComponent>>::iterator SceneSystem::CamerasEnd()
{
	return cameras.end();
}
